package com.uzai.console.web.pdd;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenIdDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenInfoDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenQuery;
import com.uzai.console.dto.pdd.pddtoken.PddTokenIdDto;
import com.uzai.console.dto.pdd.pddtoken.PddTokenInfoDto;
import com.uzai.console.dto.pdd.pddtoken.PddTokenQuery;
import com.uzai.console.entity.TlbToken;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.locallive.TlbTokenService;
import com.uzai.console.service.pdd.PddTokenService;
import com.uzai.console.vo.locallive.tlbtoken.TenMillionSubsidiesVo;
import com.uzai.console.vo.locallive.tlbtoken.TlbTokenInfoVo;
import com.uzai.console.vo.pdd.pddtoken.PddTokenAuthUrlVo;
import com.uzai.console.vo.pdd.pddtoken.PddTokenInfoVo;
import com.uzai.console.vo.pdd.pddtoken.PddTokenRecordVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "多多进宝",tags = "拼多多|多多进宝")
@ApiSort(11)
@RestController
public class PddTokenController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(PddTokenController.class);

    @Autowired
    private PddTokenService pddTokenService;
    @Autowired
    private TlbTokenService tlbTokenService;

    @ApiOperation(value = "分页查询多多进宝联盟列表", notes = "分页查询多多进宝联盟列表", response = PddTokenInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/pddToken/findPddTokenList")
    public Object findPddTokenList(@RequestBody PddTokenQuery pddTokenQuery){
        return pddTokenService.findPddTokenList(pddTokenQuery);
    }

    @SystemLogType(model = SystemModelEnum.PddToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加联盟账号", notes = "添加联盟账号", response = PddTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/pddToken/addToken")
    public Object addToken(){
        return pddTokenService.addPddToken(getLoginInfo().getMerId());
    }

    @SystemLogType(model = SystemModelEnum.PddToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "重新授权", notes = "重新授权", response = PddTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/pddToken/reauthorize")
    public Object reauthorize(){
        return pddTokenService.addPddToken(getLoginInfo().getMerId());
    }

    @ApiOperation(value = "查询联盟详情", notes = "查询联盟详情", response = PddTokenInfoVo.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/pddToken/findPddTokenInfo")
    public Object findPddTokenInfo(@RequestBody PddTokenIdDto pddTokenIdDto){
        return pddTokenService.findPddTokenInfo(pddTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.PddToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改", notes = "修改")
    @ApiOperationSupport(order = 5)
    @PostMapping("/pddToken/updatePid")
    public Object updatePid(@RequestBody PddTokenInfoDto pddTokenInfoDto){
        pddTokenService.updatePid(pddTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.PddToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 6)
    @PostMapping("/pddToken/deletePddToken")
    public Object deletePddToken(@RequestBody PddTokenIdDto pddTokenIdDto){
        pddTokenService.deletePddToken(pddTokenIdDto);
        return true;
    }

    @ApiOperation(value = "分页查询推老板拼多多列表", notes = "分页查询推老板拼多多列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/pddToken/findTlbTokenList")
    public Object findTlbTokenList(@RequestBody TlbTokenQuery tlbTokenQuery){
        if(StringUtils.isBlank(tlbTokenQuery.getType())){
            tlbTokenQuery.setType("pdd");
        }
        return tlbTokenService.findTlbTokenList(tlbTokenQuery);
    }

    @ApiOperation(value = "分页查询推老板拼多多详情", notes = "分页查询推老板拼多多详情", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/pddToken/findTlbTokenInfo")
    public Object findTlbTokenList(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        if(StringUtils.isBlank(tlbTokenIdDto.getType())){
            tlbTokenIdDto.setType("pdd");
        }
        return tlbTokenService.findTlbTokenInfo(tlbTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加推老板拼多多账号", notes = "添加推老板拼多多账号", response = TlbToken.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/pddToken/addTlbToken")
    public Object addTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        if(StringUtils.isBlank(tlbTokenInfoDto.getType())){
            tlbTokenInfoDto.setType("pdd");
        }

        TlbToken tlbToken =  tlbTokenService.addTlbToken(tlbTokenInfoDto);
        return tlbToken;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改推老板拼多多账号", notes = "修改推老板拼多多账号")
    @ApiOperationSupport(order = 9)
    @PostMapping("/pddToken/updateTlbToken")
    public Object updateTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        tlbTokenService.updateTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除推老板拼多多账户", notes = "删除推老板拼多多账户")
    @ApiOperationSupport(order = 10)
    @PostMapping("/pddToken/deleteTlbToken")
    public Object deleteTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        if(StringUtils.isBlank(tlbTokenIdDto.getType())){
            tlbTokenIdDto.setType("pdd");
        }
        tlbTokenService.deleteTlbToken(tlbTokenIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.PddToken, type = OperationTypeEnum.RECORD)
    @ApiOperation(value = "拼多多联盟备案", notes = "拼多多联盟备案", response = PddTokenRecordVo.class)
    @ApiOperationSupport(order = 11)
    @PostMapping("/pddToken/record")
    public Object recordTlbToken(@RequestBody PddTokenIdDto pddTokenIdDto){
        return pddTokenService.recordPddToken(pddTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.PddToken, type = OperationTypeEnum.RECORD)
    @ApiOperation(value = "拼多多共享联盟千万补贴申请页面", notes = "拼多多共享联盟千万补贴申请页面", response = TenMillionSubsidiesVo.class)
    @ApiOperationSupport(order = 11)
    @PostMapping("/pddToken/tenMillionSubsidies")
    public Object tenMillionSubsidies(@RequestBody PddTokenIdDto pddTokenIdDto){
        return pddTokenService.tenMillionSubsidies(pddTokenIdDto);
    }

}
